class Class2Girl {
  public readonly name: string
  constructor(private _age: number, name: string) {
    this._age = _age
    this.name = name
  }

  // 用于返回指定元素
  get age() {
    // 可以返回保存的元素
    return this._age
  }
  // 设置拦截
  set age(val: number) {
    // 如果设置的值小于18，设置为18
    if (val < 18) {
      this._age = 18
    } else {
      this._age = val
    }
  }

  static getAge() {
    console.log('hello world')
  }
}

const class2Test = new Class2Girl(28, 'ektx')
console.log(class2Test)
console.log(class2Test.age)
class2Test.age = 15
console.log(class2Test.age)
class2Test.age = 29
console.log(class2Test.age)

// 只读属性无法赋值
// class2Test.name = 'sklakl'

Class2Girl.getAge()